//
//  SaveCell.swift
//  DSP
//
//  Created by tucici on 2024/5/23.
//

import UIKit
import TCCKit
class SaveCell: UITableViewCell {
    private var name : UILabel!
    private var date : UILabel!
    private var lock : UIImageView!
    private var share : UIButton!
    var line : UIView!
    var block:(()->Void)?
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        initUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func initUI(){
        selectionStyle = .none
        backgroundColor = .clear
        
        name = UILabel()
        name.text = "测试测试"
        name.font = TCCKit.font(16,.bold)
        name.textHexColor = "#000000"
        name.minimumScaleFactor = 0.5
        name.adjustsFontSizeToFitWidth = true
        name.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
        name.setContentHuggingPriority(.defaultLow, for: .horizontal)
        
        date = UILabel()
        date.text = "mac"
        date.font = TCCKit.font(12)
        date.textHexColor = "#999999"
        date.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
        date.setContentHuggingPriority(.defaultLow, for: .horizontal)
        
        lock = UIImageView()
        lock.image = UIImage(named: "lock2")
        
        
        share = UIButton(type: .custom)
        share.setImage("export".img, for: .normal)
        share.addTarget(self, action: #selector(actionForBtn), for: .touchUpInside)
        
        line = UIView()
        line.bgHexColor = "#000000"
        
        contentView.addSubview(name)
        contentView.addSubview(date)
        contentView.addSubview(lock)
        contentView.addSubview(share)
        contentView.addSubview(line)
        
        name.snp.makeConstraints { make in
            make.bottom.equalTo(contentView.snp.centerY).offset(3)
            make.left.equalTo(lock.snp.right).offset(10)
        }
        
        date.snp.makeConstraints { make in
            make.top.equalTo(contentView.snp.centerY).offset(2)
            make.left.equalTo(name)
        }
        
        lock.snp.makeConstraints { make in
            make.height.equalTo(16)
            make.size.equalTo(lock.snp.width)
            make.left.equalToSuperview().offset(10)
            make.centerY.equalToSuperview()
        }
        
        share.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 40, height: 40))
            make.right.equalToSuperview().inset(10)
            make.centerY.equalToSuperview()
        }
        
        line.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(10)
            make.bottom.equalToSuperview()
            make.height.equalTo(0.5)
            make.top.equalToSuperview().offset(43.5)
        }
    }
    
    var model : ChannelManager!{
        didSet{
            name.text = model.name
            date.text = model.date
            lock.snp.updateConstraints { make in
                make.height.equalTo(model.isLock ? 16 : 0)
            }
            
        }
    }
    
    @objc func actionForBtn(){
        block?()
    }
}
